package top.drinyeit.weilong.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.app.Constant;
import top.drinyeit.weilong.model.WithdrawDetailBean;

/**
 * Created by wu on 2018/1/24.
 */

public class WithdrawDeatilAdapter extends RecyclerView.Adapter<WithdrawDeatilAdapter.ViewHolder> {
    private List<WithdrawDetailBean> data;
    private Context context;

    public WithdrawDeatilAdapter(List<WithdrawDetailBean> data) {
        this.data = data;
    }

    public void clear() {
        this.data.clear();
    }

    public void addData(List<WithdrawDetailBean> data) {
        this.data.addAll(data);
    }

    public void setData(List<WithdrawDetailBean> data) {
        this.data = data;
    }

    public List<WithdrawDetailBean> getData() {
        return data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_pay_details, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.balance.setText(data.get(position).getAccount_name() + data.get(position).getAccount_number());
        holder.add.setText(data.get(position).getAmount());
        holder.date.setText(data.get(position).getCreate_time());
        switch (data.get(position).getState()){
            case 0:
                holder.way.setText("待审核");
                holder.way.setTextColor(ContextCompat.getColor(context,R.color.hint_137));
                break;

            case 1:
                holder.way.setText("提现成功");
                holder.way.setTextColor(ContextCompat.getColor(context,R.color.app_green));
                break;

            case 2:
                holder.way.setText("提现失败");
                holder.way.setTextColor(ContextCompat.getColor(context,R.color.red));
                break;

        }

    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView way;
        public TextView date;
        public TextView balance;
        public TextView add;

        public ViewHolder(View itemView) {
            super(itemView);
            way = itemView.findViewById(R.id.way);
            date = itemView.findViewById(R.id.date);
            balance = itemView.findViewById(R.id.balance);
            add = itemView.findViewById(R.id.add);
        }
    }
}
